package client

import (
	con "context"
	"etcdview/mylog"
	"github.com/gin-gonic/gin"
	"go.etcd.io/etcd/clientv3"
	"time"
)

var Client = new(clientv3.Client)

func GetValue(context *gin.Context) {
	json := make(map[string]string)
	context.BindJSON(&json)
	path := json["path"]
	ctx, cancelFunc := con.WithTimeout(con.Background(), time.Second*15)
	get, err := Client.Get(ctx, path)
	if err != nil {
		mylog.Error(err.Error())
	}
	cancelFunc()
	s := string(get.Kvs[0].Value)
	context.JSON(200, s)
}
